import json
import requests
import random
import re
from hashlib import md5

from the_flash import app

USERNAME_PATTERN = re.compile(r'^\w{6,20}$')
TEL_PATTERN = re.compile(r'1[3-9]\d{9}')

def to_md5_hex(origin_str):
    """生成MD5摘要"""
    return md5(origin_str.encode('utf-8')).hexdigest()

# def gen_mobile_code(length=6):
#     """生成指定长度的手机验证码"""
#     return ''.join(random.choices('0123456789', k=length))
#
#
# @app.task()
# def send_sms_by_luosimao(mobile, message):
#     """发送短信（调用螺丝帽短信网关）"""
#     resp = requests.post(
#         url='http://sms-api.luosimao.com/v1/send.json',
#         auth=('api', 'key-ae7e4108bd5ce4da85d3395d76b599ef'),
#         data={
#             'mobile': mobile,
#             'message': message
#         },
#         timeout=10,
#         verify=False)
#     return json.loads(resp.content)


